<?php
	/**
	* Product Categories get list
	* return in Json format
	* @author trungdt
	* @since Sep 27, 2011
	* 
	* Change logs
	* Oct 2, 2011 - trungdt - Make this action compatible with product edit page
	*/
	if (!defined('EXPONENT')) exit('');
	if (exponent_permissions_check(array('administrate','configure'),$loc)){
		$parent_id=0;
		if (isset($_REQUEST['parent_id']))
			$parent_id=intval($_REQUEST['parent_id']);
		$sql="SELECT {$db->prefix}productsmodule_category.*, {$db->prefix}productsmodule_category.id where_id, (SELECT count({$db->prefix}productsmodule_category.id) FROM {$db->prefix}productsmodule_category WHERE parent_id = where_id) count_sub FROM {$db->prefix}productsmodule_category WHERE location_data = '".serialize($loc)."' AND parent_id = {$parent_id} ORDER BY rank";

		$data=$db->selectObjectsBySql($sql);

		foreach ($data as $k=>$v){
			$v->src=unserialize($v->location_data)->src;
			if ($v->count_sub > 0)
				$v->state="closed";
			// Oct 2, 2011
			// to more compatible with product edit page, we should add some fields
			$v->text=$v->title;
		}
		echo json_encode($data);
	}
	die();
?>